//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Resource Application Block
//===============================================================================

using System;
using Microsoft.Practices.EnterpriseLibrary.Configuration.Design;
using Microsoft.Practices.EnterpriseLibrary.Data.Configuration.Design;
using EntLibContrib.Resource;
using EntLibContrib.Resource.Configuration;
using EntLibContrib.Resource.Configuration.Design;

#if !NUNIT
using Microsoft.VisualStudio.TestTools.UnitTesting;
#else
using NUnit.Framework;
using TestClass = NUnit.Framework.TestFixtureAttribute;
using TestInitialize = NUnit.Framework.SetUpAttribute;
using TestCleanup = NUnit.Framework.TearDownAttribute;
using TestMethod = NUnit.Framework.TestAttribute;
#endif

namespace EntLibContrib.Resource.Configuration.Design.Tests
{
  [TestClass]
	public class DataResourceProviderNodeFixture : ConfigurationDesignHost
  {
		private static ResourceManager internalResources = InternalResourceFactory.GetResourceManager();

		[TestMethod]
		[ExpectedException(typeof(ArgumentNullException))]
		public void PassingNullDataThrowsException()
		{
			new DataResourceProviderNode(null);
		}

		[TestMethod]
		public void EnsureDataResourceProviderNodePropertyCategoriesAndDescriptions()
		{
			Assert.IsTrue(ResourceAttributesHelper.AssertResourceDescription(typeof(DataResourceProviderNode), "DatabaseInstance", internalResources["DatabaseInstanceDescription"]));
			Assert.IsTrue(ResourceAttributesHelper.AssertResourceCategory(typeof(DataResourceProviderNode), "DatabaseInstance", internalResources["CategoryProvider"]));
			Assert.IsTrue(ResourceAttributesHelper.AssertResourceDescription(typeof(DataResourceProviderNode), "ResourceBaseName", internalResources["ResourceBaseNameDescription"]));
			Assert.IsTrue(ResourceAttributesHelper.AssertResourceCategory(typeof(DataResourceProviderNode), "ResourceBaseName", internalResources["CategoryProvider"]));
		}
		
		[TestMethod]
		public void CanCreateDataResourceProviderNodeByDataType()
		{
			ConfigurationNode node = ServiceHelper.GetNodeCreationService(ServiceProvider).CreateNodeByDataType(typeof(DataResourceProviderData), new object[] { new DataResourceProviderData() });
			Assert.IsNotNull(node);
			Assert.AreEqual(typeof(DataResourceProviderNode), node.GetType());
		}

		[TestMethod]
		public void DataResourceProviderNodeTest()
		{
			string dataResourceProviderName = "DataResourceProvider";
			string databaseInstanceName = "DatabaseInstanceName";
			string resourceBaseName = "ResourceBaseName";
			ConnectionStringSettingsNode connectionStringSettingsNode = new ConnectionStringSettingsNode();
			connectionStringSettingsNode.Name = databaseInstanceName;

			DataResourceProviderNode node = new DataResourceProviderNode();
			node.Name = dataResourceProviderName;
			node.DatabaseInstance = connectionStringSettingsNode;
			node.ResourceBaseName = resourceBaseName;

			Assert.AreEqual(dataResourceProviderName, node.Name);
			Assert.AreEqual(databaseInstanceName, node.DatabaseInstance.Name);
			Assert.AreEqual(resourceBaseName, node.ResourceBaseName);

			DataResourceProviderData data = (DataResourceProviderData)node.ResourceProviderData;
			Assert.AreEqual(dataResourceProviderName, data.Name);
			Assert.AreEqual(databaseInstanceName, data.DatabaseInstanceName);
			Assert.AreEqual(resourceBaseName, data.ResourceBaseName);
		}

		[TestMethod]
		public void DataResourceProviderDataTest()
		{
			string dataResourceProviderName = "DataResourceProvider";
			string databaseInstanceName = "DatabaseInstanceName";
			string resourceBaseName = "ResourceBaseName";

			DataResourceProviderData data = new DataResourceProviderData();
			data.Name = dataResourceProviderName;
			data.DatabaseInstanceName = databaseInstanceName;
			data.ResourceBaseName = resourceBaseName;
			Assert.AreEqual(dataResourceProviderName, data.Name);
			Assert.AreEqual(databaseInstanceName, data.DatabaseInstanceName);
			Assert.AreEqual(resourceBaseName, data.ResourceBaseName);

			DataResourceProviderNode node = new DataResourceProviderNode(data);
			Assert.AreEqual(dataResourceProviderName, node.Name);
			Assert.AreEqual(databaseInstanceName, node.connectionStringName);
			Assert.AreEqual(resourceBaseName, node.ResourceBaseName);
		}
	}
}